#include <cstdio>
#include <cstring>

typedef long long ll;

const int N = 1e5 + 5;
int n, m, a[N], pos[N], tmp[N];

inline bool check(ll mid) {
  int flag = 0, cur = 1;
  memcpy(tmp, a, sizeof(a));
  for (int i = 1; i <= n; ++i)
    if (tmp[i] == 0) ++flag;
  for (int i = 1; i <= m && flag != n; i++) {
    ll life = mid;
    life -= pos[cur];
    while (tmp[pos[cur]] <= life && life > 0 && flag < n) {
      life -= tmp[pos[cur++]], ++flag;
      life -= (pos[cur] - pos[cur - 1]);
    }
    if (tmp[pos[cur]] > life && life > 0) { tmp[pos[cur]] -= life; }
  }
  return flag == n;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("hsblack.in", "r", stdin);
  freopen("hsblack.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  ll l = 0, r = 1e15, mid;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != 0) pos[++pos[0]] = l = i;
  }
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(mid)) r = mid;
    else
      l = mid + 1;
  }
  printf("%lld", r);
  return 0;
}